<template>
  <div>
    <div class="recommend_list" v-for="(item,index) in article" :key="index">
      <div class="recommend_item" @click="Articlejump(item.id)">
        <div class="post_imgText">
          <div class="post_img" v-if="item.images.length!==0">
            <img :src="item.images[0]" alt />
          </div>
          <div class="post_text">
            <div>
              <div>{{item.title}}</div>
            </div>
            <p>{{item.created_at|itemDate}}阅读 {{item.watch}}</p>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import moment from "moment";

export default {
  data() {
    return { article: null };
  },
  async mounted() {
    const res = await this.$axios.get("/posts/recommend", {
      params: this.$route.query
    });
    // console.log(res.data.data);

    this.article = res.data.data;
  },
  methods: {
    Articlejump(id) {
      console.log(id);
      this.$emit("ArticleId", id);
    }
  },
  filters: {
    itemDate(e) {
      return moment(e).format("YYYY-MM-DD HH:mm");
    }
  }
};
</script>

<style lang="less" scoped>
.recommend_item {
  display: block;
  padding: 20px 0;
  border-bottom: 1px solid #ddd;
  cursor: pointer;
  .post_imgText {
    display: flex;
    height: 80px;
  }
  .post_img {
    width: 100px;
    height: 80px;
    flex-shrink: 0;
    background: #ddd;
    overflow: hidden;
    margin-right: 10px;

    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
  }
  .post_text {
    flex: 1;
    position: relative;

    p {
      position: absolute;
      bottom: 0;
      left: 0;
      font-size: 12px;
      color: #999;
    }
  }
}
</style>